﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SpotTheMisspell.Models
{
    public class ParagraphFactory
    {
        public static  Paragraph createParagraph(int numberOfMispelledWord,int numberOfWords)
        {
            WordDefinitionDataContext dc = new WordDefinitionDataContext(WordDefinitionDataContext.ReadOnlyConnection);
            var query = from c in dc.MisspellWords select c;
            var dcg = query.ToArray();
            Paragraph result = new Paragraph();
            
            //decide the time to guess 4 seconds for each word + 1 seconds by number of word
            result.TimeToGuess = new TimeSpan(0, 0,(numberOfMispelledWord * 4 )+ numberOfWords );
            result.WordsContent = new List<Word>();
            Random rand = new Random(DateTime.Now.Millisecond);
            for (int i = 0; i < numberOfWords; i++)
            {
                int j = rand.Next(dcg.Length);
                if (rand.Next(100)<50 && numberOfMispelledWord >0)
                {
                    result.WordsContent.Add(new Word() { Content = dcg[j].Misspell + " ", Id = i, IsMisspell = true,Correction = dcg[j].Correct});
                    numberOfMispelledWord--;
                }
                else
                {
                    result.WordsContent.Add(new Word() { Content = dcg[j].Correct + " ", Id = i, IsMisspell = false});
                }

            }
            return result;
        }
    }
}
